package cn.droidlover.xdroidmvp.net;

import android.text.TextUtils;

import java.util.List;

public class ApiException extends RuntimeException {

    /**
     * 未知错误
     */
    public static final int UNKNOWN = 1000;
    /**
     * 解析错误
     */
    public static final int PARSE_ERROR = 1001;
    /**
     * 连接错误
     */
    public static final int NETWORD_ERROR = 1002;
    /**
     * 读取超时
     */
    public static final int TIME_OUT_ERROR = 1003;

    /**
     * IllegalStateException
     */
    public static final int ILLEGAL_STATE_ERROR= 1004;

    //后台服务器绑定微信相关错误
    public static final int WEIXIN_login_TYPE = 2001;
    public static final int YES_VIP_TYPE = 2002;
    public static final int VERIFICATION_CODE_TYPE = 2003;
    public static final int WEIXIN_BANGDING_TYPE = 2004;
    public static final int WEIXIN_OPEN_ID_TYPE = 2005;
    public static final int INVITATION_CODE_TYPE = 2006; //登陆成功
    public static final int INPUT_INVITATION_CODE_TYPE = 2007;
    public static final int YES_INVITE_TYPE = 2008;
    public static final int WEIXIN_AUTHORIZATION_TYPE = 2009;
    public static final int AUTHORIZATION_DATA_TYPE = 2010;
    public static final int INELIGIBLE_USER = 501;//不符合条件用户
    public static final int TOKEN_OUT_DATA = 401; //重新登陆
    public static final int UNBIND_WEIXIN = 301;
    public static final int MOBILE_RIGHT = 4002;//账号不存在
    public static final int PAY_PSW_ERROR = 4003;//支付密码错误
    public static final int BALANCE_INSUFFICIENT = 4004;//余额不足
    public static final int YOUMI_INSUFFICIENT = 6001;//优米不足
    public static final int GOODS_OBTAINED = 5003;//商品下架
    //正常状态码组 2001,2002,2003,2004,2005,2006,2007,2008,2009,2010
    public static final int[] codes = {200,111, 201,2006,8888};//201  跳转绑定邀请码

    private String msg;
    private int code;

    public String data;
    public ApiException(int code,String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }
    public ApiException(int code,String msg,String data) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public ApiException(int code) {
        this.code = code;
    }

    public String getMsg() {
//        if (!TextUtils.isEmpty(msg)){
//            return msg;
//        }
//        switch (code) {
//            case WEIXIN_login_TYPE://已经登陆
//                msg = "已经登录";
//                break;
//            case YES_VIP_TYPE://已是VIP
//                msg = "已是VIP";
//                break;
//            case VERIFICATION_CODE_TYPE://验证码错误
//                msg = "验证码错误";
//                break;
//            case WEIXIN_BANGDING_TYPE://微信已绑定
//                msg = "微信已绑定";
//                break;
//            case WEIXIN_OPEN_ID_TYPE://openId异常
//                msg = "openId异常";
//                break;
//            case INVITATION_CODE_TYPE://马上使用邀请码激活账号
//                msg = "马上使用邀请码激活账号";
//                break;
//            case INPUT_INVITATION_CODE_TYPE://输入邀请码不存在
//                msg = "输入邀请码不存在";
//                break;
//            case YES_INVITE_TYPE://已是邀请用户
//                msg = "已是邀请用户";
//                break;
//            case WEIXIN_AUTHORIZATION_TYPE://微信授权失败
//                msg = "微信授权失败";
//                break;
//            case UNBIND_WEIXIN:
//                msg = "未绑定微信";
//                break;
//            case AUTHORIZATION_DATA_TYPE://微信授权异常
//                msg = "微信授权异常";
//                break;
//            case TOKEN_OUT_DATA:
//
//                break;
//            //以下网络错误或者服务器
//            case UNKNOWN://
//                msg = "未知错误";
//                break;
//            case PARSE_ERROR://
//                msg = "解析错误";
//                break;
//            case NETWORD_ERROR://
//                msg = "连接错误";
//                break;
//            default:
//                msg = "网络错误";
//                break;
//        }
        return msg;
    }

    public int getCode() {
        return code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setCode(int code) {
        this.code = code;
    }

//    @Override
//    public String getMessage() {
//        return message;
//    }

//    public void setMessage(String message) {
//        this.message = message;
//    }

    @Override
    public String toString() {
        return "ApiException{" +
                "msg='" + msg + '\'' +
                "data='" + data + '\'' +
                ", code=" + code +
                '}';
    }
}
